package com.ksyun.campus.metaserver.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * MinFS configuration properties
 */
@Data
@Component
@ConfigurationProperties(prefix = "minfs")
public class MinfsProperties {
    
    private ZooKeeperConfig zookeeper = new ZooKeeperConfig();
    private MetadataConfig metadata = new MetadataConfig();
    private ClusterConfig cluster = new ClusterConfig();
    private HeartbeatConfig heartbeat = new HeartbeatConfig();
    private FsckConfig fsck = new FsckConfig();
    private DataServerConfig dataserver = new DataServerConfig();
    
    @Data
    public static class ZooKeeperConfig {
        private String connectionString = "127.0.0.1:2181";
        private int sessionTimeout = 30000;
        private int connectionTimeout = 15000;
        private RetryConfig retry = new RetryConfig();
        private String rootPath = "/minfs";
        
        @Data
        public static class RetryConfig {
            private int baseSleepTime = 1000;
            private int maxRetries = 3;
        }
    }
    
    @Data
    public static class MetadataConfig {
        private String dataDir = "./data/metaserver";
        private RocksDBConfig rocksdb = new RocksDBConfig();
        
        @Data
        public static class RocksDBConfig {
            private boolean enable = true;
            private String path = "./data/metaserver/rocksdb";
            private long writeBufferSize = 67108864L; // 64MB
            private int maxWriteBufferNumber = 3;
            private int level0FileNumCompactionTrigger = 8;
            private long maxBytesForLevelBase = 268435456L; // 256MB
        }
    }
    
    @Data
    public static class ClusterConfig {
        private int replicationFactor = 3;
        private long blockSize = 524288L; // 512KB
        private String instanceId;
        
        public String getInstanceId() {
            if (instanceId == null || instanceId.trim().isEmpty()) {
                instanceId = java.util.UUID.randomUUID().toString();
            }
            return instanceId;
        }
    }
    
    @Data
    public static class HeartbeatConfig {
        private int timeoutSeconds = 25;
        private int checkIntervalSeconds = 10;
    }
    
    @Data
    public static class FsckConfig {
        private int intervalSeconds = 60;
        private boolean enabled = true;
    }
    
    @Data
    public static class DataServerConfig {
        private ClientConfig client = new ClientConfig();
        
        @Data
        public static class ClientConfig {
            private int connectTimeout = 5000;
            private int readTimeout = 30000;
            private int maxRetries = 3;
        }
    }
}
